home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / INPUTS.ZIP / INPUT.DOC < prev    next >
Encoding:
Text File  |  1991-02-25  |  16.3 KB  |  390 lines

  1.      The functions presented here add to the programmer's tools or
  2. libraries functions that emulate Clipper's input functions for character,
  3. numeric, date, and logical field input with more functionality. The
  4. interface is simple and straightforward.  Nested input is also possible
  5. which does not have to be emulated as in Clipper's input functions.  If
  6. nested input is done, you don't have to worry about the cursor location on
  7. return from nested input as the functions will restore the cursor on
  8. return.  All functions can be exited by pressing the escape key, tab key,
  9. or enter key. If more input functions follow, input will go to the next
  10. field for input.  The only date format accepted is MM/DD/YY.  If a date
  11. field is being input, only a valid date will be accepted.  If an invalid
  12. date is forced (by leaving the field), the date array is set to all spaces
  13. (ie: '  /  /  ').  This makes for very versatile data input that increases
  14. the programmer's proficiency and adds a more professional input package
  15. that cannot be achieved from standard library input routines.  The code is
  16. small (about 8K) and does not create tremendous overhead in the executable
  17. file.  The code is available in object format only.  The SMALL model is in
  18. public domain for your use.  The LARGE model objects can be purchased for a
  19. fee of $19.95 plus $3.00 shipping and handling.  California residents add
  20. applicable sales taxes.  Mail orders to:
  21.  
  22.                         LPC Software
  23.                         1250 Cloverglen Dr.
  24.                         Valinda, Ca.  91744
  25.  
  26.  
  27. ----------------------------------------------------------------
  28.      These are the six functions that you need to use.  One each for the
  29. different types of inputs that you create.  The types of inputs accepted
  30. are:
  31.         string : inputs characters and character numbers
  32.          alpha : inputs alpha characters only
  33.        logical : inputs logical only (Y or N)
  34.       long int : inputs long integers only (-2,147,483,648 to              
  35.                                2,147,483,647)
  36.         double : inputs floating point numbers up to 80 digits
  37.           date : inputs a valid date with format MM/DD/YY
  38.  
  39. Plus two lower level function:
  40. 1.  waitkey() : simulates getch() filtering out exception keys.  This
  41. function takes no arguments and returns nothing.
  42. 2.  getKeyExtended() : This function takes no arguments and returns a
  43. 'keycodes' structure defined in the INPUT header file.  This function can
  44. be used to control a while loop looking for only one key on the keyboard. 
  45. See example below.
  46.  
  47.      Each input function is prototyped in the INPUT.H file.   This is what
  48. the prototypes look like:
  49.  
  50.       void    inputString(char *, int, void (*func)(char));
  51.  
  52.       void    inputAlpha(char *, int, void (*func)(char));
  53.  
  54.       char    inputLogical(char, void (*func)(char));
  55.  
  56.       long    inputLong(int, void (*func)(char));
  57.  
  58.       double  inputDouble(int, int, void (*func)(char));
  59.  
  60.       void    inputDate(char *, void (*func)(char));
  61.  
  62. Notice the declaration "void (*func)(char)" in the argument list for these
  63. prototypes.  These are the functions that you write that will be executed
  64. when an exception key is pressed, ie: F1, F2, <ALT><A>, etc.  If one of
  65. these keys is pressed, the function passed will be executed.  This is how
  66. nested input can be achieved or help screens popped up. No trapping is done
  67. for the <CTRL><C> or <CTRL><BREAK> key.  If one of these two keys is
  68. pressed, the program will abort unless you have redefined these exception
  69. handlers elsewhere in your code or have disabled them.  Consult your
  70. reference manuals on how to do this.
  71.  
  72.  
  73. 'void (*func)(char)' further defined:
  74.    This is a pointer to a function that accepts a character (the exception
  75. key pressed) that returns nothing.  The name 'func' is arbitrary and must
  76. be prototyped as 'void func(char)' in your main file or a header file; or
  77. 'void handler(char)'; or whatever name you want to use.  This function will
  78. be called if an exception key is pressed while entering data into one of
  79. the types above and must exist even if it does nothing.  Here is a complete
  80. example that demonstrates this:
  81.  
  82. void func(char);            /* The prototype for your function */
  83. long LongIntegerNumber;     /* A variable to place an int      */
  84.  
  85. void main(void) {
  86.    LongIntegerNumber = inputLong(10, func);
  87.    do_whatever_with(LongIntegerNumber);
  88. }
  89.  
  90. void func(key_received) {
  91.    int i:   /* This will convert the character to an int */
  92.    i = key_received;
  93.    if (i == F1)
  94.       do_whatever_F1_is_supposed_to_do();
  95.    return;
  96. }
  97.  
  98. A handler must be defined for each of the six high level input functions
  99. even though is doesn't do anything. All high level functions begin with the
  100. word "input".  If you want nothing done in your handler, simply put a
  101. return statement inside.  For example:
  102.  
  103.    void func(key_received) {
  104.       return;
  105.    }
  106.  
  107. and pass this function as an argument to the high level input function.
  108.  
  109.      There is also two other functions in the library for your use.  These
  110. functions are waitkey() and getKeyExtended().  waitkey()'s prototype is
  111. 'void waitkey(void)' and is in the INPUT header file.  If you create nested
  112. input, it is highly recommended that you use this function for a keypress
  113. to return to the calling function.  If you use getch() or any other
  114. function and the user presses a function key consecutively without a call
  115. to another nested input function, unpredictable results may occur.  The
  116. prototype for getKeyExtended is 'struct keycodes getKeyExtended(void) and
  117. is also in the INPUT header file.  Do not mix the standard library input
  118. routines within these routines.  Standard input can be used with no problem
  119. in all modules as long as one of these six input routines aren't being used
  120. for input.
  121.  
  122. ////////////////////////////////////////////////////////////////
  123.             The functions usage are described below.
  124. ////////////////////////////////////////////////////////////////
  125. To input a string:
  126.    Use the function - void inputString(char *, int, void (*func)(char));
  127.    This function takes three parameters which are (1) a pointer to an
  128. array, (2) the size of the array (always allow one character more in the
  129. array for the terminating null character in the string, use sizeof), and
  130. (3) the function name to be executed for an exception key.  In the long
  131. integer example above, the function name is 'func'.  Here is another
  132. example:
  133.  
  134.    #include "input.h"
  135.    void StringHandler(char);
  136.    char string[21];
  137.  
  138.    void main(void) {
  139.       inputString(string, sizeof string, StringHandler);
  140.       printf("string is: %s\n", string);
  141.    }
  142.  
  143.    void StringHandler(char excpt_key) {
  144.       printf("\nHandler executed with key %d\n", excpt_key);
  145.       return;
  146.    }
  147.  
  148. This example simply inputs the string.  If an exception key is pressed
  149. while inputting the string, the StringHandler is executed and prints the
  150. message "Handler executed with key 59" if F1 was pressed during input.
  151.  
  152.  
  153. ////////////////////////////////////////////////////////////////////////
  154. To input an alpha string:
  155.    Use the function - void inputAlpha(char *, int, void (*func)(char));
  156.    The format for usage is exactly like that of the input string function. 
  157. The only characters that are allowed to be input are the letters A thru Z
  158. and a thru z.
  159.  
  160.  
  161. ////////////////////////////////////////////////////////////////////////
  162. To input a logical:
  163.    use the function - char inputLogical(char, void (*func)(char));
  164.    This takes two parameters which are (1) the actual character field where
  165. the logical input is to be placed, and (2) a function name that is to be
  166. executed if an exception key is pressed.  Here is an example:
  167.  
  168.    #include <input.h>
  169.    void LogicalHandler(char);  /* your handler prototype  */
  170.    char YesNo;                 /* field for logical input */
  171.    YesNo = 'Y';
  172.  
  173.    void main(void) {
  174.       YesNo = inputLogical(YesNo, logHandler);
  175.       if (YesNo == 'Y') {
  176.          .
  177.          .
  178.       } else {
  179.          .
  180.          .
  181.       }
  182.  
  183.    void logHandler(key) {
  184.       int the_key;
  185.  
  186.       the_key = key;  /* Remember to convert to int */
  187.       if (the_key == F1) {
  188.          .
  189.          .
  190.       }
  191.          .
  192.          .
  193.       if (the_key == F10)
  194.          exit(0); /* Standard library function will close all files. */
  195.       return;
  196.    }
  197.  
  198. It is not important that YesNo be set to a 'Y' or 'N'.  If YesNo is null
  199. when this function is executed, it will be set according to the key pressed
  200. for logical input.  If it is not set when called and the user hits the
  201. escape key or return key without entering anything, it will be set to 'N'
  202. otherwise 'Y'.
  203.  
  204.  
  205. ////////////////////////////////////////////////////////////////////////
  206. To input long integers:
  207.    Use the function - int inputLong(int, void (*func)(char));
  208.    This function takes two parameters which are (1) the number of digits to
  209. be input.  This number cannot exceed twelve (max digits would be ten
  210. characters in 2147483648 plus a preceding minus sign plus a terminating
  211. null character all used internally within the inputLong function.  (2) The
  212. second parameter is a function to execute if an exception key is pressed. 
  213. The inputLong() function will return the value of the long integer input. 
  214. The range of this functions return value is -2,147,483,648 to 2,147,483,647
  215. inclusive. Make sure that you do not allow input beyond these ranges.  This
  216. can be achieved by passing a smaller number of digits to be input thereby
  217. limiting the range of input.  If you pass twelve as the number of digits to
  218. be input, there is no guarantee that the operator will not input a '9' as
  219. the first digit followed by nine more digits well exceeding the range for a
  220. long integer and still being able to enter more.  For numeric input beyond
  221. the ranges of this function, use the inputDouble() function. If nothing is
  222. input, zero is return.  An example of usage follows:
  223.  
  224.    #include "input.h"
  225.    void handler(char);    /* prototype your handler */
  226.    long LNumber;
  227.  
  228.    long main(void) {      /* don't know why anybody would do this */
  229.       LNumber = inputLong(6, handler);
  230.       return(Number);
  231.    }
  232.  
  233.    void handler(key) {    /* your handler */
  234.       if (key == F10)     /* will quit the program if F10 is pressed */
  235.          exit(0);
  236.       return;
  237.    }
  238.  
  239.  
  240. ////////////////////////////////////////////////////////////////////////
  241. To input doubles:
  242.    use function - double inputDouble(int, int, void (*func)(char));
  243.    This function takes three parameters that are (1) the number of digits
  244. that will be accepted including the decimal point and terminating
  245. character.  If the number is greater than 80, the function will return a
  246. zero. So the maximum field size for input on the screen is eighty.  (2) The
  247. second parameter is the number of decimal places that will be accepted. 
  248. For dollar amounts, this value would be two. (3) The third parameter is the
  249. function to be executed for an exception key.  For example:
  250.  
  251.    #include "input.h"
  252.    void anotherhandler(char);   /* prototype your function */
  253.    double Number;
  254.  
  255.    void main(void) {
  256.       Number = inputDouble(20, 2, anotherhandler)
  257.       printf("\n%f\n", Number);
  258.    }
  259.  
  260.    void anotherhandler(key) {
  261.       if (key == F1)
  262.          doHelpScreen();   /* defined elsewhere in your program */
  263.       if (key == F10)
  264.          exit(0);          /* program will exit here if F10 pressed */
  265.       return;
  266.    }
  267.  
  268. This function will return a double and assigned it to a variable.
  269. ////////////////////////////////////////////////////////////////////////
  270. To input dates:
  271.    use function - void inputDate(char *, void (*func)(char))
  272.    This function take two parameters that are (1) a string that holds the
  273. array "  /  /  ".  This is in fact an array of nine characters.  Eight are
  274. visible and the ninth is the terminating null character '\0'.  Only valid
  275. dates are accepted and will adjust for leap years.  The only format
  276. accepted is MM/DD/YY.  For the year 2000, YY would be 00.  Here is an
  277. example:
  278.  
  279.    #include "input.h"
  280.    void datefunc(char);         /* Your exception handler */
  281.    char date[] = "  /  /  ";    /* Must have this format  */
  282.  
  283.    void main(void) {
  284.       inputDate(date, datefunc);
  285.          .
  286.          .
  287.       return;
  288.    }
  289.  
  290.    void datefunc( ch ) {
  291.       int key;
  292.  
  293.       key = ch;
  294.       do_whatever_with( key );
  295.       return;
  296.    }
  297.  
  298. ////////////////////////////////////////////////////////////////////////
  299. To wait for a keypress:
  300.    use function - void waitkey(void)
  301.    This function will filter out any exception keys and will return only if
  302. A-Z, 0-9, ENTER, SPACE, TAB, or RETURN is pressed. For example:
  303.  
  304.    #include <conio.h>   /* for clrscr() */
  305.    #include "input.h"
  306.    void main(void) {
  307.       clrscr();
  308.       waitkey();
  309.       return;
  310.    }
  311.  
  312. This simple program will clear the screen and wait for a key to be pressed. 
  313. Once a key is pressed, the program will exit back to DOS.
  314. ////////////////////////////////////////////////////////////////////////
  315. To get a key value from the keyboard:
  316.    use function struct keycodes getKeyExtended(void)
  317.    This function will return the key pressed or the extended key pressed as
  318. defined by the keycodes structure in the INPUT header file.  If a normal
  319. key is pressed, its value is placed in the keycodes key location. If an
  320. exception key is pressed (ie: F1, F2, ALT1, etc.), its value will be placed
  321. in the keycodes scancode location.  Here is an example on how to use this
  322. function:
  323.  
  324.    #include "input.h"
  325.  
  326.    void main(void) {
  327.  
  328.       struct keycodes input;   /* declare a structure */
  329.  
  330.       do {
  331.          input = getKeyExtended();
  332.       } while (input.key != 'q');
  333.    }
  334.  
  335. This small program will run until a 'q' is pressed on the keyboard.
  336. ////////////////////////////////////////////////////////////////////////
  337.      If your handler functions do anything such as popping up a window or
  338. nested input or simply displays a message on the screen in any given
  339. location, the cursor will be restored to the original position on the
  340. screen from where the handler function was called during input.  All the
  341. high level input functions do this so you can write your handler functions
  342. without having to worry about the cursor when inputting a field.
  343. ////////////////////////////////////////////////////////////////////////
  344. If you are interested in purchasing the large model library, send a check
  345. for $19.95 plus $3.00 for shipping and handling.  You will receive both
  346. the small model and large model libraries.  California residents add
  347. applicable sales tax.  Make check out to: LPC Software and mail to:
  348.  
  349.                     LPC Software
  350.                     1250 Cloverglen Dr.
  351.                     Valinda, Ca. 91744
  352.  
  353. If you are a Compuserve user, questions and suggestions may be sent via
  354. E-MAIL to 74106,3500.
  355.  
  356.          ----------------end-of-author's-documentation---------------
  357.  
  358.                         Software Library Information:
  359.  
  360.                    This disk copy provided as a service of
  361.  
  362.                         The Public (Software) Library
  363.  
  364.          We are not the authors of this program, nor are we associated
  365.          with the author in any way other than as a distributor of the
  366.          program in accordance with the author's terms of distribution.
  367.  
  368.          Please direct shareware payments and specific questions about
  369.          this program to the author of the program, whose name appears
  370.          elsewhere in  this documentation. If you have trouble getting
  371.          in touch with the author,  we will do whatever we can to help
  372.          you with your questions. All programs have been tested and do
  373.          run.  To report problems,  please use the form that is in the
  374.          file PROBLEM.DOC on many of our disks or in other written for-
  375.          mat with screen printouts, if possible.  The P(s)L cannot de-
  376.          bug programs over the telephone.
  377.  
  378.          Disks in the P(s)L are updated monthly, so if you did not get
  379.          this disk  directly from the P(s)L,  you should be aware that
  380.          the files in this set may no  longer be the current versions.
  381.  
  382.          For a copy of the latest monthly software library newsletter
  383.          and a list of the 2,000+ disks in the library, call or write
  384.  
  385.                         The Public (Software) Library
  386.                               P.O.Box 35705
  387.                            Houston, TX 77235-5705
  388.                                (713) 524-6394
  389.  
  390.